// pages/charge/charge.js
const app = getApp();
import httpUtil from '../../utils/httpUtil'
Page({

  /**
   * 页面的初始数据
   */
  data: {
      month:1,
      price:20,
      storeId: null
  },
  selected(e){
    console.log(e.currentTarget.dataset.price)
    console.log(e.currentTarget.dataset.month)
    var month = e.currentTarget.dataset.month;
    var price = e.currentTarget.dataset.price;
    this.setData({
      month:month,
      price:price
    })
  },

  renew(e){
    var that = this;
    var storeId = this.data.storeId
    var price = this.data.price
    var month = this.data.month
     httpUtil.getRequest('/api/store/renew',{
         'storeId':storeId,
         'month': month,
         'price':price
     }).then(res=>{
       console.log(res)
       wx.requestPayment(
           {
             "timeStamp": res.timestamp,
             "nonceStr": res.noncestr,
             "package": res._package,
             "signType": "MD5",
             "paySign": res.paySign,
             "complete":function(res){

             },
             "fail":function(res){},
             "success":function(res){
                 console.log("支付成功")
                 wx.showToast({
                  title: '支付成功',
                })
                wx.reLaunch({
                    url: '/pages/index/index'
                })
                 
             }
           }
         )
     })
 },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad(options) {
    var storeId = options.storeId;
    this.setData({
        storeId:storeId,
    })
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady() {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow() {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide() {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload() {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh() {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom() {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage() {

  }
})